package com.ruoyi.oa.controller;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.oa.domain.OaFile;
import com.ruoyi.oa.service.IOaFileService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文件Controller
 * 
 * @author luguanqing
 * @date 2022-02-09
 */
@RestController
@RequestMapping("/oa/file")
public class OaFileController extends BaseController
{
    @Autowired
    private IOaFileService oaFileService;

    /**
     * 查询文件列表
     */
    @GetMapping("/list")
    public TableDataInfo list(OaFile oaFile)
    {
        startPage();
        List<OaFile> list = oaFileService.selectOaFileList(oaFile);
        return getDataTable(list);
    }

    /**
     * 获取文件树列表
     */
    @GetMapping("/treeselect")
    public AjaxResult treeselect(OaFile oaFile)
    {
        List<OaFile> oaFiles = oaFileService.selectOaFileList(oaFile);
        return AjaxResult.success(oaFileService.buildDeptTree(oaFiles));
    }

    /**
     * 导出文件列表
     */
    @Log(title = "文件", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OaFile oaFile)
    {
        List<OaFile> list = oaFileService.selectOaFileList(oaFile);
        ExcelUtil<OaFile> util = new ExcelUtil<OaFile>(OaFile.class);
        return util.exportExcel(list, "file");
    }

    /**
     * 获取文件详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(oaFileService.selectOaFileById(id));
    }

    /**
     * 新增文件
     */
    @Log(title = "文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OaFile oaFile)
    {
        return toAjax(oaFileService.insertOaFile(oaFile));
    }

    /**
     * 修改文件
     */
    @Log(title = "文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OaFile oaFile)
    {
        return toAjax(oaFileService.updateOaFile(oaFile));
    }

    /**
     * 删除文件
     */
    @Log(title = "文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(oaFileService.deleteOaFileByIds(ids));
    }
}
